const { resolve } = require('path');
const WebpackBar = require('webpackbar');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { devPort, title } = require('./src/config/vue.custom.config');

module.exports = {
  css: {
    loaderOptions: {
      less: {
        javascriptEnabled: true
      }
    }
  },
  devServer: {
    hot: true,
    port: devPort,
    open: true,
    noInfo: false,
    overlay: {
      warnings: true,
      errors: true,
    },
    proxy: {
      '/api': {
        target: 'https://wifi.12306.cn/operatemonit/wifiapps/ordercenter-query-front-end/api',
        ws: false,
        changeOrigin: true,
        pathRewrite: {
          '^/api': '',
        },
      },
    }
  },
  configureWebpack() {
    return {
      resolve: {
        alias: {
          '@':resolve('src'),
        },
      },
      plugins: [
        new WebpackBar({
          name: title,
        })
      ],
    }
  },
  chainWebpack: (config) => {
    config.plugin('html').tap((options) => {
      options[0].title = title;
      return options;
    })
  },
};